package com.aote.entity.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.w3c.dom.Element;

import com.aote.mvc.event.Action;
import com.browsesoft.baseadapter.AdvancedSimpleEntity;

/**
 * 给onload增加内容的action，要替换onload的#id#为对象id。
 */
public class WriteOnloadAction extends Action {
	public void performAction(Element config, HttpServletRequest request,
			Map attrs) {
		// 得到模型id
		AdvancedSimpleEntity model = (AdvancedSimpleEntity) component
				.getModel();
		String id = model.getID();
		// 得到配置的onload，替换#id#为对象id
		String onload = config.getAttribute("onload");
		onload = onload.replaceAll("#id#", id);
		// 替换page_name
		String pageName = component.getPage().getName();
		onload = onload.replaceAll("#page_name#", pageName);
		// 设置组件的onload属性
		this.component.getPage().addOnload(onload);
	}
}
